#include "page_login.h"
#include "ui_page_login.h"
#include<QPainter>
#include<QSqlDatabase>
Page_login::Page_login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Page_login)
{
    ui->setupUi(this);
    stu=stuSql::getinstance();
   // stu->init();
}

Page_login::~Page_login()
{
    delete ui;
}

void Page_login::paintEvent(QPaintEvent *)
{
    //设置背景图片
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/img/story.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

//登录
void Page_login::on_btn_login_clicked()
{
   QString username =ui->le_user->text();
   QString password =ui->le_password->text();

   bool result=stu->login(username,password);
   if(username==NULL||password==NULL){
       QMessageBox::warning(this,"错误","账号密码为空");
       return;
   }
   if(result){
       this->hide();
       w.show();
   }
   else{
       QMessageBox::warning(this,"错误","账号密码错误");
       ui->le_user->clear();
       ui->le_password->clear();
       return;
   }
}
//退出
void Page_login::on_btn_exit_clicked()
{
    exit(0);
}
